//
//  YiDatabase+Tools.swift
//  yiplayer
//
//  Created by wkun on 2024/6/13.
//

import UIKit

extension YiDatabase {
    func deleteData(ID:String?, dataBase: FMDatabase?, tableName: String?) -> Bool{
        if ID == nil || dataBase == nil || tableName == nil {
            return false
        }
        
        if (dataBase?.isOpen ?? false) == false {
            dataBase?.open()
        }
        
        let sql = "DELETE FROM \(tableName!) WHERE ID=\(ID!)";
        return dataBase!.executeUpdate(sql, withArgumentsIn: [])
    }
    
    func getDatas(sql: String?, dataBase:FMDatabase?) -> FMResultSet? {
        if sql == nil || dataBase == nil {
            return nil
        }
        if (dataBase?.isOpen ?? false) == false {
            dataBase?.open()
        }
        
        do {
            let r = try dataBase?.executeQuery(sql!, values: nil)
            return r
        } catch{
            
        }
        return nil
    }
}

